Because both of the old values of the point's X and Y coordinates are used in both of these equations, you must be careful when using the equations in Visual Basic. You might try to execute the statements in order like this:
X = X * Cos(theta) - Y * Sin(theta)
Y = X * Sin(theta) + Y * Cos(theta)
Unfortunately the first statement changes the value of the variable X. The original value of X is not available for use in the second statement, so the new value for Y is wrong. The following three lines show one way you can rotate a point correctly in Visual Basic.
new_x = X * Cos(theta) - Y * Sin(theta)
Y = X * Sin(theta) + Y * Cos(theta)
X = new_x
Figure 12.12 shows a small picture before and after rotation through an angle of 30 degrees.
The Mathematics of Rotation
This section explains why the rotation equations described in the previous section work. If your trigonometry is a little rusty, feel free to skip this section and take the equations on faith.
To see why the rotation equations work, look at Figure 12.13. The point (x1, y1) is distance R from the origin. Using simple trigonometry, you know that:
x1 = R * Cos(f)
y1 = R * Sin(f)
The point (x2, y2) is the same point rotated by an angle of q. Because it is also distance R from the origin, its coordinates are given by: